package com.hck.trigger.http;


import com.hck.domain.consultation.model.entity.ConsultationReplyEntity;
import com.hck.domain.consultation.model.entity.HealthConsultationEntity;
import com.hck.domain.consultation.service.IConsultationService;
;
import com.hck.types.model.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/consultation")
@Tag(name = "咨询接口", description = "咨询相关操作")
public class ConsultationController {

    @Resource
    private IConsultationService consultationService;

    // 创建咨询
    @PostMapping("/create")
    @Operation(summary = "用户咨询", description = "用户咨询")
    public Response<Long> createConsultation(@RequestBody HealthConsultationEntity consultation) {
        Long id = consultationService.createConsultation(consultation);
        return Response.<Long>builder()
                .info("创建咨询成功")
                .data(id)
                .code("200")
                .build();
    }

    // 回复咨询
    @PostMapping("/{id}/reply")
    @Operation(summary = "医生回复咨询", description = "医生回复咨询")
    public Response<Void> replyConsultation(@PathVariable Long id, @RequestBody ConsultationReplyEntity reply) {
        consultationService.replyConsultation(id, reply);
        return Response.<Void>builder()
                .info("回复咨询成功")
                .data(null)
                .code("200")
                .build();
    }

    // 查询咨询详情
    @GetMapping("/{id}")
    @Operation(summary = "查询咨询详情", description = "查询咨询详情")
    public Response<HealthConsultationEntity> getConsultationDetail(@PathVariable Long id) {
        return Response.<HealthConsultationEntity>builder()
                .code("200")
                .data(consultationService.getConsultationDetail(id))
                .info("查询成功")
                .build();
    }

    // 查询咨询回复
    @GetMapping("/{id}/replies")
    @Operation(summary = "查询咨询回复", description = "查询咨询回复")
    public Response<List<ConsultationReplyEntity>> getReplies(@PathVariable Long id) {
        return Response.<List<ConsultationReplyEntity>>builder()
                .code("200")
                .data(consultationService.getReplies(id))
                .info("查询成功")
                .build();
    }

    // 查询用户的咨询列表
    @GetMapping("/user/{userId}")
    @Operation(summary = "查询用户的咨询列表", description = "查询用户的咨询列表")
    public Response<List<HealthConsultationEntity>> getUserConsultations(@PathVariable Long userId) {
        return Response.<List<HealthConsultationEntity>>builder()
                .code("200")
                .data(consultationService.getUserConsultations(userId))
                .info("查询成功")
                .build();
    }

    // 查询医生的咨询列表
    @GetMapping("/doctor/{doctorId}")
    @Operation(summary = "查询医生的咨询列表", description = "查询医生的咨询列表")
    public Response<List<HealthConsultationEntity>> getDoctorConsultations(@PathVariable Long doctorId) {
        return Response.<List<HealthConsultationEntity>>builder()
                .code("200")
                .data(consultationService.getDoctorConsultations(doctorId))
                .info("查询成功")
                .build();
    }

    @PostMapping("/{id}/close")
    @Operation(summary = "结束咨询会话", description = "将会话状态设为closed")
    public Response<Void> closeConsultation(@PathVariable Long id) {
        consultationService.closeConsultation(id);
        return Response.<Void>builder()
                .info("会话已结束")
                .data(null)
                .code("200")
                .build();
    }
}